// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Loader.java

package canvas;

import java.io.IOException;
import javax.microedition.lcdui.*;

// Referenced classes of package mquran:
//            Quran, QuranCanvas

public class Loader extends Canvas
    implements Runnable
{
    class LoadResource extends Thread
    {

        public void run()
        {
            loadRsc(0);
            d.setRunning(false);
            try
            {
                Thread.sleep(200L);
            }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }
            Quran.show(quran);
        }

        private Loader d;

        public LoadResource(Loader d, int type)
        {
            this.d = d;
        }
    }


    public Loader(QuranCanvas quran)
    {
        running = true;
        str = "Loading...";
        inc = 0;
        setFullScreenMode(true);
        this.quran = quran;
        try
        {
            imgLoader1 = Image.createImage("/images/loader1.png");
            imgLoader2 = Image.createImage("/images/loader2.png");
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }

    public static Loader getInstance(QuranCanvas quran)
    {
        if(null == instance)
            instance = new Loader(quran);
        return instance;
    }

    public void paint(Graphics g)
    {
        g.setFont(Font.getFont(0, 1, 0));
        g.setColor(0xffdd66);
        g.fillRect(0, 0, g.getClipWidth(), g.getClipHeight());
        int x = getWidth() / 2 - (imgLoader1.getWidth() * 5) / 2;
        int y = getHeight() / 2 - imgLoader1.getHeight() / 2;
        for(int i = 0; i < inc; i++)
        {
            g.drawImage(imgLoader1, x, y, 20);
            x += imgLoader1.getWidth();
        }

        for(int i = inc; i < 5; i++)
        {
            g.drawImage(imgLoader2, x, y, 20);
            x += imgLoader1.getWidth();
        }

        inc++;
        if(inc > 5)
            inc = 0;
        g.setColor(0x92d74e);
        y += imgLoader1.getHeight() + 2;
        x = getWidth() / 2 - g.getFont().stringWidth(str) / 2;
        g.drawString(str, x, y, 20);
    }

    public void startLoader(int type, int pilih)
    {
        this.pilih=pilih;
        Quran.show(this);
        inc = 0;
        running = true;
        (new Thread(this)).start();
        (new LoadResource(this, type)).start();
    }

    public void loadRsc(int type)
    {
        quran.openSurah(type, pilih);
    }

    public void run()
    {
        while(running) 
        {
            repaint();
            try
            {
                Thread.sleep(200L);
            }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }

    public void setRunning(boolean running)
    {
        this.running = running;
    }

    private boolean running;
    private String str;
    private static Loader instance = null;
    private QuranCanvas quran;
    private Image imgLoader1;
    private Image imgLoader2;
    private int inc;
    int pilih=0;


}
